<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增知识课堂类别')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-dept-add">
        <input id="treeId" name="parentId" th:value="${kc.kctypeId}" type="hidden"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">上级分类：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" required id="treeName" onclick="selectKCTypeTree()" readonly="true" th:value="${kc.kcTypeName}"
                           type="text">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">知识课堂名称：</label>
            <div class="col-sm-8">
                <input class="form-control" required id="kcTypeName" name="kcTypeName" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">知识课堂编码：</label>
            <div class="col-sm-8">
                <input class="form-control" required id="code" name="code" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">显示顺序：</label>
            <div class="col-sm-8">
                <input class="form-control" required id="orderNum" name="orderNum" type="number">
            </div>
        </div>


    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "system/ncKnowledgeClassType";

    $("#form-dept-add").validate({
        onkeyup: false,
        rules: {
            caiName: {
                remote: {
                    url: prefix + "/checkYaoNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "parentId": function () {
                            return $("input[name='parentId']").val();
                        },
                        "kcTypeName": function () {
                            return $.common.trim($("#kcTypeName").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            orderNum: {
                digits: true
            },
            email: {
                email: true,
            },
            phone: {
                isPhone: true,
            },
        },
        messages: {
            "caiName": {
                remote: "知识课堂类别已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-dept-add').serialize());
        }
    }

    function selectKCTypeTree() {
        var options = {
            title: '知识课堂选择',
            width: "380",
            url: prefix + "/selectKCTypeTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }
</script>
</body>
</html>
